package cn.chenhongchao.zhaobiaopingtai.controller;

import cn.chenhongchao.zhaobiaopingtai.common.api.CommonResult;
import cn.chenhongchao.zhaobiaopingtai.dto.SupplierLoginData;
import cn.chenhongchao.zhaobiaopingtai.service.ISupplierLpginDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Optional;

@Api(value = "供应商模块模块", tags = "供应商信息接口")
@RestController
@CrossOrigin
@RequestMapping("/tenderRequest")
public class UserLoginController {

    @Resource
    private ISupplierLpginDataService supplierLpginDataService;

    @Resource
    protected BCryptPasswordEncoder bCryptPasswordEncoder;

    @ApiOperation(value = "查询供应商信息", notes = "登录验证")
    @RequestMapping(value = "/getSupplierByMaterialCateGory", method = RequestMethod.POST)
    public CommonResult getCurrentUserLogin(String sso_sessionid,@RequestBody SupplierLoginData supplierLoginData) {
        System.out.println();
        if (supplierLoginData.getSupplierName() == null
        || supplierLoginData.getPassword() == null) {
            return CommonResult.validateFailed("登录失败！！");
        }
        final Boolean flag = supplierLpginDataService.login(supplierLoginData.getSupplierName(),
                bCryptPasswordEncoder.encode(supplierLoginData.getPassword()));

        if (flag) {

//            UserInfoDTO dto = new UserInfoDTO();
//
//            // 设置账号信息
//            dto.setAccount(account);
//
//            Optional<UserBasicInfo> infoOptional = basicInfoService.getOptionalByPhone(account.getName());
//
//            // 设置用户基础信息
//            infoOptional.ifPresent(dto::setBasicInfo);

            return CommonResult.success("登陆成功！！");
        }

        return CommonResult.failed("账号信息错误！请重新输入！");
    }

}
